package mllib

import org.apache.spark.mllib.linalg
import org.apache.spark.mllib.linalg.Vectors

/**
 * DESC:本地向量--mllib的vector
 */
object _01localVector {
  def main(args: Array[String]): Unit = {
    //dense稠密性向量----需要将0值和非0值全部存在于数据中心
    val vector1: linalg.Vector = Vectors.dense(1.0, 2.0, 3.0)
    val vector2: linalg.Vector = Vectors.dense(Array(1.0, 2.0, 0.0, 0.0, 0.0))
    println("vector value is:", vector1) //(vector value is:,[1.0,2.0,3.0])
    println("vector1 value is:", vector1(0)) //(vector1 value is:,1.0)
    //dense稀疏向量----仅仅存储的非0值的下标和对应的取值，而不存储0值对应下标和取值
    val vector: linalg.Vector = Vectors.sparse(4, Array(0, 2), Array(1.0, 3.0))
    println(vector)
    println(vector(0))
    println(vector(1))
    println(vector(3))
  }
}
